package com.example.aijie.autoreadhelper;

import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.example.aijie.autoreadhelper.service.AutoReadService;
import com.example.aijie.autoreadhelper.service.NewsAppMonitorService;
import com.example.aijie.autoreadhelper.utils.PermissionHelper;

import org.litepal.LitePal;
import org.litepal.tablemanager.callback.DatabaseListener;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFormat(PixelFormat.TRANSLUCENT);
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onResume() {
        super.onResume();
        PermissionHelper.hasOverlay(this);
        if (!PermissionHelper.isAccessibilitySettingsOn(this)) {
            Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
            startActivity(intent);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_start_service:
                startService(new Intent(this, AutoReadService.class));
                startService(new Intent(this, NewsAppMonitorService.class));
                break;
            case R.id.btn_stop_service:
                stopService(new Intent(this, AutoReadService.class));
                stopService(new Intent(this, NewsAppMonitorService.class));
                break;
        }
    }
}
